<?php
if($_GET['mode']=="edit"){
   if($_POST['submit_article']!=true) echo '';
   else {
      $select_u = mysql_query('SELECT teacher_to FROM users WHERE username = "'.$_SESSION['username'].'"');
      $row_u = mysql_fetch_assoc($select_u);
	  
      $article_name = addslashes(trim(htmlspecialchars($_POST['article_name'])));
	  $article_descr = addslashes(trim(htmlspecialchars($_POST['article_descr'])));
	  $content= addslashes(trim($_POST['myTextArea']));
	  $place= $_POST['module'];
	  
	  if(empty($article_name) || empty($article_descr) || empty($content)){
	     echo '<p class="error">Моля, попълнете ВСИЧКИ полета!</p>';
	  } else {
	     $sel_m = mysql_query('SELECT article_name FROM articles WHERE article_name = "'.$article_name.'" AND from_who = "'.$_SESSION['username'].'" AND article_id != '.$_GET['id'].'');
		 if(mysql_num_rows($sel_m) != 0){
		    echo '<p class="error">Името на статията е заето!</p>';
		 } else {
		    if(strlen($article_name)<3 || strlen($article_descr)<3 || strlen($content)<3){
			   echo '<p class="error">Кратко име и/или описание и/или статия</p>';
			} else {
			   $update='UPDATE articles SET article_name="' . $article_name. '", article_descr="'. $article_descr . '", content="'.$content.'", place="'.$place.'" WHERE article_id='.$_GET['id'].'';
		       $res_update=mysql_query($update);
			   echo '<p class="success">Успешно обновяване!</p>';
			   echo '<meta http-equiv="refresh" content="1;url=editarticle.php">';
			} 
		 }
	  }
   }
}
?>